// hyb_yl/doctorHome/pages/set_chargedata/set_chargedata.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    title:"",
    content:"",
    time_length:"",
    money:"",
    equiment_id:"",
    equiment_list:"",
    status:0, 
    sercive_list:"",
  },
  switch_btn:function(e){
    var checked=e.detail.value;
    this.setData({
      status:e.detail.value
    })
  },
  money_input:function(e){
    this.setData({
      money:e.detail.value
    })
  },
  // 选择时间
  choose_date:function(e){
    var index=e.detail.value;
    this.setData({
      date_text:this.data.date_list[index].title
    })
  },

  // 选择服务
  choose_fuwu:function(e){
    var index=e.detail.value;
    this.setData({
      fuwu_text:this.data.date_list[index].title
    })
  },
  determine:function(e){
    var that = this;
    var status=this.data.status;//是否开启
    var money=this.data.money;//设置价格
    var money=this.data.date_text;//服务时间
    var money=this.data.fuwu_text;//服务内容
    var title = that.data.title;
    return
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var status = options.status;
    var id = options.id;
    if(id != undefined && id != 'undefined')
    {
      that.setData({
        id:id
      })
    }
    that.setData({
      status:status,
      zid:options.zid
    })
    // 获取设备列表
    that.getShebei();
    // 获取服务
    that.getService();
    // 获取服务详情
    that.getDetail();
  },
  // 获取设备列表
  getShebei:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.equement_list",
      success:function(res)
      {
        console.log(res)
        that.setData({
          equiment_list:res.data
        })
      }
    })
  },
  title_input:function(e){
    this.setData({
      title:e.detail.value
    })
  },
  content_input:function(e){
    this.setData({
      content:e.detail.value
    })
  },
  time_input:function(e){
    this.setData({
      time_length:e.detail.value
    })
  },
  money_input:function(e){
    this.setData({
      money:e.detail.value
    })
  },
  // 输入次数
  number_input:function(e){
    var index = e.target.dataset.index;
    console.log(e);
    var that = this;
    var sercive_list = that.data.sercive_list;
    sercive_list[index].number = e.detail.value;
    that.setData({
      sercive_list:sercive_list
    })
  },
  // 获取服务列表
  getService:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.service_list",
      data:{
        id:that.data.id
      },
      success:function(res)
      {
        that.setData({
          sercive_list:res.data
        })
      }
    })
  },
  // 获取详情
  getDetail:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.fuwu_content",
      data:{
        id:that.data.id
      },
      success:function(res)
      {
        that.setData({
          detail:res.data,
          equiment_id:res.data.equiment_id,
          equiment_title:res.data.equiment_list[0].title,
          service:res.data.contain
        })
      }
    })
  },
  // 选择设备
  choose_equiment:function(e){
    var that = this;
    var equiment_list = that.data.equiment_list;
    var index = e.detail.value;
    var equiment_title = equiment_list[index].title
    var equiment_id = equiment_list[index].id
    that.setData({
      equiment_title:equiment_title,
      equiment_id:equiment_id
    })
  },
  // 修改收费设置
  determine:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/follow.edit_fuwu",
      data:{
        id:that.data.id,
        zid:that.data.zid,
        title:that.data.title,
        content:that.data.content,
        equiment_id:that.data.equiment_id,
        money:that.data.money,
        time_length:that.data.time_length,
        status:that.data.status,
        contain:JSON.stringify(that.data.sercive_list),
      },
      success:function(res)
      {
        wx.navigateBack({})
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})